package com.mb.app.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.domain.TbSpecsCfg;
import com.mb.app.dao.TbSpecsCfgMapper;
import com.mb.app.service.ITbSpecsCfgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 规格属性配置  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-04-01
 */
@Service
@Slf4j
public class TbSpecsCfgServiceImpl extends ServiceImpl<TbSpecsCfgMapper, TbSpecsCfg> implements ITbSpecsCfgService {


    @Override
    public List<TbSpecsCfg> queryList(Map<String, Object> map) {
        List<TbSpecsCfg> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.countt(map);
    }

    @Override
    public int save(TbSpecsCfg TbSpecsCfg) {
        TbSpecsCfg.setCreateTime(new Date());
        return this.baseMapper.insert(TbSpecsCfg);
    }

    @Override
    public int update(TbSpecsCfg TbSpecsCfg) {
        try {
            TbSpecsCfg TbSpecsCfg1 = new TbSpecsCfg();
            TbSpecsCfg1.setSpecsId(TbSpecsCfg.getSpecsId());
            TbSpecsCfg1.setDataStatus(1);
            TbSpecsCfg TbSpecsCfgDO = this.baseMapper.selectOne(TbSpecsCfg1);
            if(TbSpecsCfgDO != null){
                TbSpecsCfg.setUpdateTime(new Date());
                this.baseMapper.updateById(TbSpecsCfg);
            }
        } catch (Exception e) {
            log.error("update Exception",e);
        }
        return 0;
    }


    @Override
    public int remove(Long specsId,Long delUserId) {
//        return this.baseMapper.deleteById(appId);
        TbSpecsCfg TbSpecsCfg = new TbSpecsCfg();
        TbSpecsCfg.setSpecsId(specsId);
        TbSpecsCfg.setDeleteTime(new Date());
        TbSpecsCfg.setDataStatus(0);
        TbSpecsCfg.setDeleteUserId(delUserId);
        return this.baseMapper.updateById(TbSpecsCfg);
    }

    @Override
    public TbSpecsCfg getDtl(Long bannerId) {
        TbSpecsCfg TbSpecsCfg = this.baseMapper.selectById(bannerId);
        return TbSpecsCfg;
    }

    @Override
    public boolean specsCfgsNameExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectBySpecsInfo(params).size() > 0;
        return exit;
    }

    @Override
    public List<TbSpecsCfg> getSpecsList(Map<String, Object> map) {
        return this.baseMapper.getSpecsList(map);
    }

    @Override
    public TbSpecsCfg insertSelective(TbSpecsCfg specsCfg) {
        int str =  this.baseMapper.insertSelective(specsCfg);
        return specsCfg;
    }


}
